package com.ykdl.member.kid.adapters;

import java.util.List;

import com.lidroid.xutils.BitmapUtils;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.beans.InvitationBean;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class InvatationListAdapter extends BaseAdapter{
    private Context mContext;
    private BitmapUtils bitmapUtil;
    private List<InvitationBean> list;
    public InvatationListAdapter(Activity context){
    	this.mContext=context;
    	bitmapUtil=new BitmapUtils(mContext);
    }
    public void setList(List<InvitationBean> list){
    	this.list=list;
    }
    
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (list!=null) {
			return list.size();
		}else {
			return 0;
			
		}
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder=null;
		if(convertView==null){
			convertView=RelativeLayout.inflate(mContext, R.layout.item_invitation_list, null);
			holder=new ViewHolder();
			holder.inv_img=(ImageView) convertView.findViewById(R.id.inv_img);
			holder.inv_desc=(TextView) convertView.findViewById(R.id.inv_desc);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		bitmapUtil.configDefaultLoadingImage(R.drawable.circle_default);
		bitmapUtil.configDefaultLoadFailedImage(R.drawable.circle_default);
		if(null!=list.get(position).getDetails_pic()){
				bitmapUtil.display(holder.inv_img, list.get(position).getDetails_pic().getUrl());
		}
		holder.inv_desc.setText(list.get(position).getTitle());
		return convertView;
	}

	class ViewHolder{
		ImageView inv_img;
		TextView inv_desc;
	}
}
